package _interview75;

/**
 * 643. 子数组最大平均数 I
 */
public class No643 {
    public double findMaxAverage(int[] nums, int k) {
        int n = nums.length;

        double curAvg = 0;
        for (int i = 0; i < k; i++) {
            curAvg += nums[i];
        }

        double answer = curAvg / k;
        for (int left = 0, right = k; right < n; left++, right++) {
            curAvg = curAvg - nums[left] + nums[right];
            answer = Math.max(curAvg / k, answer);
        }

        return answer;
    }
}
